﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
	<script src="../../static/js/jquery-3.5.1.min.js" th:src="@{/js/jquery-3.5.1.min.js}"></script>
	<link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css" th:href="@{/h-ui/css/H-ui.min.css}"/>
	<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css" th:href="@{/h-ui.admin/css/H-ui.admin.css}"/>
	<link rel="stylesheet" type="text/css" href="../../static/lib/Hui-iconfont/1.0.8/iconfont.css" th:href="@{/lib/Hui-iconfont/1.0.8/iconfont.css}"/>
	<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin" th:href="@{/h-ui.admin/skin/default/skin.css}"/>
	<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css" th:href="@{/h-ui.admin/css/style.css}"/>
	<link rel="stylesheet" href="../../static/Semantic-UI-master/dist/semantic.min.css" th:href="@{/Semantic-UI-master/dist/semantic.min.css}">
	<link rel="stylesheet" href="../../static/css/custom.css" th:href="@{/css/custom.css}">

<title>用户管理</title>
</head>
<script type="text/javascript" th:inline="javascript">
	$(function () {
		if(![[${session.admin}]]){
			alert("请先去登录")
			window.location.replace("/sy/syadmin/admin")
		}
	})

</script>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c m-padded-t-middle">
		<div class="" style="padding-bottom: 10px">
			<input class="searchinput1 prompt" type="text" id="searchinput" placeholder="用户搜索......">
			<button class="searchbutton1 ui teal button" id="searchbutton"><i class="search icon"></i></button>
		</div>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l"><a href="javascript:;" onclick="member_add('添加用户','member-add.html','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a></span>
		在考虑要不要做这个功能
		<span class="r">共有数据：<strong th:text="${session.syuserofadmin.size()}" id="datanum">1</strong> 条</span> </div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th width="80">ID</th>
				<th width="100">用户名</th>
				<th width="100">头像</th>
				<th width="150">权限</th>
				<th width="70">手机</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody id="searchshow">
			<tr class="text-c" th:each="syuser:${session.syuserofadmin}">
				<td th:text="${syuser.userId}">1</td>
				<td th:text="${syuser.userName}">张三</td>
				<td><img th:src="${syuser.userImg}" src="https://edu-linagyu-sy.oss-cn-shenzhen.aliyuncs.com/Imges/0f6a15acf0864b80b44bdcd87e52d07esx.jpg" style="width: 60px;height: auto;"></td>

                <td th:if="${syuser.userPrivilege}==0" class="userprivilege">学生</td>
                <td th:unless="${syuser.userPrivilege}==0" class="userprivilege">教师</td>
				<td th:text="${syuser.userPhone}">15678475291</td>
				<td class="td-manage">
                    <a style="text-decoration:none" class="ml-5" th:onClick="change_privilege(this,[[${syuser.userId}]])" href="javascript:;" title="权限修改"><i class="Hui-iconfont">&#xe63f;</i></a>
                    <a title="注销用户" href="javascript:;" th:onclick="user_del(this,[[${syuser.userId}]])" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
			</tr>
		</tbody>
	</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->

<script type="text/javascript" src="../../static/lib/layer/2.4/layer.js" th:src="@{/lib/layer/2.4/layer.js}"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js" th:src="@{/h-ui/js/H-ui.min.js}"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js" th:src="@{/h-ui.admin/js/H-ui.admin.js}"></script> <!--/_footer 作为公共模版分离出去-->
<script src="../../static/js/jquery-ui.min.js" th:src="@{/js/jquery-ui.min.js}"></script>
<script src="../../static/Semantic-UI-master/dist/semantic.min.js" th:src="@{/Semantic-UI-master/dist/semantic.min.js}"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../static/lib/My97DatePicker/4.8/WdatePicker.js" th:src="@{/lib/My97DatePicker/4.8/WdatePicker.js}"></script>
<script type="text/javascript" src="../../static/lib/datatables/1.10.0/jquery.dataTables.min.js" th:src="@{/lib/datatables/1.10.0/jquery.dataTables.min.js}"></script>
<script type="text/javascript" src="../../static/lib/laypage/1.2/laypage.js" th:src="@{/lib/laypage/1.2/laypage.js}"></script>
<script type="text/javascript">

/*用户-添加*/
function member_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*用户-权限*/
function change_privilege(obj,id){
    layer.confirm('权限只能在学生和教师之间变换，确认修改',function(index){
        $.ajax({
            type: 'POST',
            url: '/sy/syuser/changePri',
            cache: false,
            data: {'userId':id},
            success: function(data){
				$(obj).parents("tr").find(".userprivilege").text(data);
                layer.msg('权限修改成功',{icon:1,time:1000});
            },
            error:function(data) {
                layer.msg('出错了',{icon:0,time:1000});
            },
        });
    });
}

/*用户-注销*/
function user_del(obj,id){
    layer.confirm('确认要注销该用户吗？',function(index){
        $.ajax({
            type: 'POST',
            url: '/sy/syuser/deleteuser',
            cache: false,
            data: {'userId':id},
            success: function(data){
                $(obj).parents("tr").remove();
                layer.msg('已注销!',{icon:1,time:1000});
            },
            error:function(data) {
                layer.msg('为了数据安全，您不能删除该用户',{icon:0,time:1000});
            },
        });
    });
}

//搜索
$("#searchbutton").click(function () {
    var text = $("#searchinput").val();
    $.ajax({
        type: "get",
        cache: false,
        url: "/sy/syuser/search",
        data: {"searchstr":text},
        contenType: "application/json;charset=utf-8",
        success: function (data) {

            if(data.length==0){
                layer.msg('没有搜索到内容',{icon:0,time:2000});
            }else {
                $("#datanum").text(data.length);
                var htmls = '';

                for(let i=0; i<data.length; i++){
					var aaa = '';
                	if(data[i].userPrivilege==0) aaa='学生'
					else aaa='教师'
                    var add ='<tr class="text-c">\n' +
							'\t\t\t\t<td>'+data[i].userId+'</td>\n' +
							'\t\t\t\t<td>'+data[i].userName+'</td>\n' +
							'\t\t\t\t<td><img src="'+data[i].userImg+'" style="width: 60px;height: auto;"></td>\n' +
							'        <td class="userprivilege">'+aaa+'</td>\n' +
							'\t\t\t\t<td>'+data[i].userPhone+'</td>\n' +
							'\t\t\t\t<td class="td-manage">\n' +
							'              <a style="text-decoration:none" class="ml-5" onClick="change_privilege(this,'+data[i].userId+')" href="javascript:;" title="权限修改"><i class="Hui-iconfont">&#xe63f;</i></a>\n' +
							'               <a title="注销用户" href="javascript:;" onclick="user_del(this,'+data[i].userId+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>\n' +
							'\t\t\t</tr>';


                    htmls += add;
                }
                $("#searchshow").html(htmls);
            }
        },
        error: function (message) {
            layer.msg('出错了',{icon:0,time:1000});
        }
    })

})
</script> 
</body>
</html>